import { IncomingMessage } from "http";
import ws from "ws";

export class WebSocketServer extends ws.Server {
    public isListenning: boolean = false;
    listen() {
        this.on("close", () => {
            if (this.onClose) {
                this.onClose();
            }
        });

        this.on("connection", (socket: ws, req: IncomingMessage) => {
            if (this.onConnection) {
                this.onConnection(socket, req);
            }
        });

        this.on("error", (error) => {
            if (this.onClose) {
                this.onClose(error);
            }
        });

        this.on("listening", () => {
            this.isListenning = true;
        });
    }

    onConnection(socket: ws, req: IncomingMessage) {

    };

    onClose(error?: Error) {

    }
}